package com.ljsw.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface.OnKeyListener;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.ljsw.activity.R;
/**
 * 删除自定义Dialog
 * 作者: 石锚
 * 版本: 1.0
 * 日期: 2015-10-10
 */
public class DeleteDialog {
	public DeleteDialog(Context context) {
		super();
		this.context = context;
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		display = windowManager.getDefaultDisplay();//获取屏幕分辨率
	}
	private Context context;
	private Dialog dialog;
	private Display display;
	private LinearLayout lLayout_bg;
	private TextView delete_title;//标题
	private Button queding,quxiao;//确定|取消
	
	
	public DeleteDialog builder(){
		// 获取Dialog布局
		View view = LayoutInflater.from(context).inflate(R.layout.view_deletedialog, null);
		lLayout_bg = (LinearLayout) view.findViewById(R.id.lLayout_bg);
		delete_title = (TextView) view.findViewById(R.id.delete_title);
		queding = (Button) view.findViewById(R.id.queding_delete);
		quxiao = (Button) view.findViewById(R.id.quxiao_delete);
		//添加Dialog样式
		dialog = new Dialog(context, R.style.DeleteDialog);
		dialog.setContentView(view);
		// 调整dialog背景大小
		lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams((int) (display.getWidth() * 0.85), LayoutParams.WRAP_CONTENT));
		return this;
	}
	/**
	 * 设置标题
	 * @param title
	 * @return
	 */
	public DeleteDialog setTitle(String title){	
		delete_title.setText(title);
		return this;
	}
	
	public DeleteDialog setOnlyButton(){
		quxiao.setVisibility(View.GONE);
		return this;
	}
	
	public DeleteDialog setkeyListener(OnKeyListener listener){
		dialog.setOnKeyListener(listener);
		dialog.setCancelable(false);
		return this;
	}
	/**
	 * 确定事件
	 * @param text
	 * @param listener
	 * @return
	 */
	public DeleteDialog setPositiveButton(String text,
			final OnClickListener listener) {
		
		queding.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				listener.onClick(v);
				dialog.dismiss();
			}
		});
		return this;
	}
	/**
	 * 取消事件
	 * @param text
	 * @param listener
	 * @return
	 */
	public DeleteDialog setNegativeButton(String text,
			final OnClickListener listener) {
		quxiao.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				listener.onClick(v);
				dialog.dismiss();
			}
		});
		return this;
	}
	
	public void show() {
		dialog.show();
	}


}
